<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>主页</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/plugins/build/css/app.css" media="all">
</head>

<body>
<div class="container">
    <form class="layui-form" action="">
        <input type="hidden" name="orderId" value=""/>
        <div class="layui-form-item">
            <label class="layui-form-label">订单编号</label>
            <div class="layui-input-block">
                <input type="text" name="orderSn" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">第三方支付单号</label>
            <div class="layui-input-block">
                <input type="text" name="outerSn" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">购买者ID</label>
            <div class="layui-input-block">
                <input type="text" name="buyerId" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">购买者名称</label>
            <div class="layui-input-block">
                <input type="text" name="buyerName" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">购买平台: 0PC  1安卓  2IOS  3微信</label>
            <div class="layui-input-block">
                <input type="text" name="buyerPlatform" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">购买方式: 0余额  1微信  2支付宝</label>
            <div class="layui-input-block">
                <input type="text" name="payMode" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支付时间</label>
            <div class="layui-input-block">
                <input type="text" name="payTime" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支付留言</label>
            <div class="layui-input-block">
                <input type="text" name="payMsg" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支付状态: 0未付款  1已付款</label>
            <div class="layui-input-block">
                <input type="text" name="payStatus" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单状态: 0:已取消;  10:待付款;  20:待发货;  30:待收货;  40:交易完成</label>
            <div class="layui-input-block">
                <input type="text" name="orderState" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单总金额</label>
            <div class="layui-input-block">
                <input type="text" name="orderTotalPrice" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单支付金额</label>
            <div class="layui-input-block">
                <input type="text" name="orderPayPrice" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">运费价格</label>
            <div class="layui-input-block">
                <input type="text" name="orderFreightPrice" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单创建时间</label>
            <div class="layui-input-block">
                <input type="text" name="createTime" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item custom_layer_bottom_btn">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="save">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/plugins/layui/layui.js"></script>
<script src="/plugins/common.js"></script>
<script>
    //配置项：详情地址、添加地址
    var detailUrl = SERVER_URL+"/shopOrder/detail";
    var editUrl = SERVER_URL+"/shopOrder/edit";

    layui.use(['jquery', 'form'], function() {
        var $ = layui.jquery;
        var form = layui.form;

        //配置项：初始化表单数据
        function initForm(data) {
            $("input[name='orderId']").val(data.orderId);
            $("input[name='orderSn']").val(data.orderSn);
            $("input[name='outerSn']").val(data.outerSn);
            $("input[name='buyerId']").val(data.buyerId);
            $("input[name='buyerName']").val(data.buyerName);
            $("input[name='buyerPlatform']").val(data.buyerPlatform);
            $("input[name='payMode']").val(data.payMode);
            $("input[name='payTime']").val(data.payTime);
            $("input[name='payMsg']").val(data.payMsg);
            $("input[name='payStatus']").val(data.payStatus);
            $("input[name='orderState']").val(data.orderState);
            $("input[name='orderTotalPrice']").val(data.orderTotalPrice);
            $("input[name='orderPayPrice']").val(data.orderPayPrice);
            $("input[name='orderFreightPrice']").val(data.orderFreightPrice);
            $("input[name='createTime']").val(data.createTime);
        }

        //判断新增or修改
        if(urlParam("id")){
            $.ajax({
                type: 'GET',
                url: detailUrl,
                data: {id: urlParam("id")},
                success: function (result) {
                    if(result.code == 20000){
                        initForm(result.data);
                    }else{
                        layer.msg(result.msg, {time: 1500});
                    }
                }
            });
        }

        //新增or修改
        form.on('submit(save)', function(data){
            $.ajax({
                type: 'POST',
                url: editUrl,
                data: data.field,
                success: function (result) {
                    if(result.code == 20000){
                        parent.reload();
                    }else{
                        layer.msg(result.msg, {time: 1500});
                    }
                }
            });
            return false;
        });
    });

    //地址栏参数
    function urlParam(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)	return unescape(r[2]);
        return null;
    }
</script>
</body>

</html>
